home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 7796 < prev    next >
Encoding:
Text File  |  1996-08-05  |  2.6 KB  |  116 lines

  1. Path: ix.netcom.com!netnews
  2. From: lewkbj@ix.netcom.com (leonel wizel )
  3. Newsgroups: comp.lang.c++
  4. Subject: I need some help with a homework
  5. Date: 19 Feb 1996 02:43:27 GMT
  6. Organization: Netcom
  7. Message-ID: <4g8o4f$m93@ixnews7.ix.netcom.com>
  8. NNTP-Posting-Host: ix-nyc20-01.ix.netcom.com
  9. X-NETCOM-Date: Sun Feb 18  6:43:27 PM PST 1996
  10.  
  11.  
  12. I need some help with a homework, that is very difficult for me to
  13. figure it out.  I understand the concept of the language but I am
  14. having trouble to find wharever I am doing wrong.
  15.  
  16. The program suppose to
  17.  
  18. Enter hours worked (-1 to end): 39
  19. enter hourly rate of the worker ($00:00): 10.00
  20. salary is $390.00
  21.  
  22. Enter hours worked (-1 to end): 40
  23. enter hourly rate of the worker ($00:00): 10.00
  24. salary is $400.00
  25.  
  26. Enter hours worked (-1 to end): 41
  27. Enter hourly rate of the worker ($00:00): 10.00
  28. salary is $415.00
  29.  
  30. Enter hours worked (-1 to end): -1
  31.  
  32. no more hours to enter.
  33.  
  34. the following program I wrote but, only gives me one amout which is
  35. $390.00, it supposse to give me the second amount which is 400.00
  36. but, it keeps repeating the same figure which is 390.00
  37.  
  38. I need some help please;
  39.  
  40. The program is as follows:
  41.  
  42. #include <iostream.h>
  43. #include <iomanip.h>
  44.  
  45. main()
  46. {
  47. //initialization phase
  48.  
  49. float hour_rate, salary, hours_worked;
  50.  
  51.  
  52. cout << "Enter hours worked (-1 to end): ";
  53. cin >> hours_worked;
  54.  
  55.     if (hours_worked != 1)
  56.     {
  57.     cout << "Enter hourly rate of the  worker ($00.00): ";
  58.     cin >> hour_rate;
  59.     }
  60.  
  61. //processing phase
  62.     
  63.     while (hours_worked != -1)
  64.     {
  65.     if (hours_worked > 40)
  66.         {
  67.         salary = hours_worked * hour_rate + (hour_worked * 1.5 * hour_rate);
  68.         }
  69.     else
  70.         salary = hours_worked * hour_rate;
  71.  
  72.     cout << "The salary for the employee is: \n"
  73.          << setiosflags(ios::fixed | ios::showpoint)
  74.          << setprecision(2) << salary << endl;
  75.  
  76.     cout << endl;
  77.  
  78.     cout <<"Enter hours worked (-1 to end): ";
  79.     cin >> hour_rate;
  80.  
  81.     if (hours_worked != -1)
  82.         {
  83.         cout << "Enter hourly rate of the worker ($00.00): ";
  84.         cin >> hour_rate;
  85.         }
  86.     }
  87.  
  88. //termination phase
  89.  
  90. if (hours_worked == -1)
  91.     {
  92.     cout << endl;
  93.     cout << "no hours were entered";
  94.     }
  95.  
  96. return 0;
  97. }
  98.  
  99. the problem is that is giving only one figure which is $390.00, and
  100. then is 
  101. not clearing the buffer and when I enter another number is keeps the
  102. same amount in memory which is 390.00.  If I tried to end it, it won't
  103. end it will give me the second line which is "Enter hourly rate of the
  104. worker ($00.00): ";
  105.  
  106. I need some help with this simple program for some but, very difficult
  107. for me.
  108.  
  109. Thank you.
  110.  
  111.  
  112.     
  113.     
  114.  
  115.  
  116.